package com.yx.strategy.factory;

import com.yx.strategy.DownStrategy;
import com.yx.strategy.bean.EnumStrategy;

/**
 * @author: dlr
 * @data: 2019/10/27 22:48
 * @desc:工厂模式+枚举类实现策略模式
 */
public class StrategyFactory {

    public static DownStrategy getDownStrategy(String type){
        try{
            //1.通过枚举获取到每个具体得实现类得class地址
            String className=EnumStrategy.valueOf(type).getClassName();
            //2.通过反射得到类
            return (DownStrategy)Class.forName(className).newInstance();
        }
        catch (Exception e){
            return null;
        }
    }
}
